//
//  UIBarButtonItem+LS_BarButtonCustom.m
//  breadPro
//
//  Created by 刘文超 on 2019/7/5.
//  Copyright © 2019 刘文超. All rights reserved.
//

#import "UIBarButtonItem+LS_BarButtonCustom.h"

@implementation UIBarButtonItem (LS_BarButtonCustom)


+(UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action image:(NSString *)image selectImage:(NSString *)selectImage
{
    UIButton *btn = [UIBarButtonItem buttonWithTarget:target action:action image:image selectImage:selectImage title:nil];
    UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:btn];
    return item;
}
+(UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action title:(NSString *)title
{
    UIButton *btn = [UIBarButtonItem buttonWithTarget:target action:action image:nil selectImage:nil title:title];
     UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return item;
}
/**
 *  辅组方法,用来创建自定义按钮,并且文字显示文字,是自定义的
 */
+ (UIButton *)buttonWithTarget:(id)target action:(SEL)action image:(NSString *)image selectImage:(NSString *)selectImage title:(NSString *)title
{
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    UIImage * imageNormal = [UIImage imageNamed:image];
    UIImage * imageSelect = [UIImage imageNamed:selectImage];
    
    [btn setBackgroundImage:imageNormal forState:UIControlStateNormal];
    [btn setBackgroundImage:imageSelect forState:UIControlStateHighlighted];
    
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateHighlighted];
    CGRect rect = btn.frame;
    rect.size = imageNormal.size;
    btn.frame = rect;
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    //让文字 显示在 按钮的下方
    btn.titleLabel.font = [UIFont systemFontOfSize:10];
    //设置文字内边距
    btn.titleEdgeInsets = UIEdgeInsetsMake(btn.frame.size.height * 0.5 , 0, 0, 0);
    
    return btn;
}

@end
